#define ssss functions that belong to api2

from worklist import *
from google.appengine.ext import db
mylists = []


def showWorkitems(limit, user):
    #compare
    for x in worklists:
        if user.roles in x.assigned_roles:
              mylists.append(x)
        else:
            continue

    for i in range(limit):
            print 'worklist', mylists[i].name
            for j in range(len(mylists[i])):
               print i, ' . ', mylists[i][j].name

def myWorklist(user):
    myones = []
    al = db.GqlQuery('SELECT * FROM worklist')
    for item in al:
        if item.isInRoles(user.roles):
            myones.append(item)
    return myones
    
    
def showNextItem(user):
    return mylist[0]

def checkoutItem(workitemId):
    mylist.pop()
    workitem.status = 'inprogress'

def checkinItem(workitemId):
    for x in workitem.workitems:
        if (x.workitemid == workitemId):
            workitem.status = 'done'
                           
def updateItem(workitemId, comments):
    for x in workitem.workitems:
        if (x.workitemid == workitemId):
            workitem.comments = comments




